package com.dymedia.aibo.app;

import android.content.Context;
import android.graphics.Color;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.WindowManager;
import android.widget.TextView;
import android.widget.Toast;

import com.dymedia.aibo.BuildConfig;
import com.dymedia.aibo.R;
import com.dymedia.aibo.app.utils.Utils;
import com.dymedia.aibo.mvp.model.api.Api;

import me.jessyan.art.base.BaseApplication;
import timber.log.Timber;

public class MainApp extends BaseApplication {
    static MainApp mMainApp;
    DisplayMetrics dm = new DisplayMetrics();
    public static String APP_DOMAIN_HTTP="http://59.124.143.229:60080";
    public static String APP_DOMAIN_API_USA = "http://195.154.102.249:3000"; //usa
    public static String APP_DOMAIN_API_ASIA = "http://62.210.110.184:3000"; //asia
    public static String APP_DOMAIN_API =
            "http://59.124.143.229:3000";
            //"http://120.25.166.214:3000";
            //"http://192.168.1.200:3000";
            //"http://192.168.125.100:3000";
            //"http://192.168.31.100:3000";
            //"http://172.20.10.5:3000";
            //"http://192.168.100.226:3000";

    @Override
    public void onCreate() {
        super.onCreate();
        mMainApp = this;

        if (!BuildConfig.DEBUG) {
            APP_DOMAIN_API = "http://59.124.143.229:3000";
        }

        WindowManager wm = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
        wm.getDefaultDisplay().getMetrics(dm);
        recycleViewHeight = dm.heightPixels;
        recycleViewHeightChannel = dm.heightPixels;

        Log.e("Aibo", String.format("onCreate, uid: %s, version: %s, height: %d, api: %s", Utils.getUid(), BuildConfig.VERSION_NAME, recycleViewHeight, APP_DOMAIN_API));
        Timber.d(Utils.getProductInfo(this));
    }

    public static MainApp instance(){
        return mMainApp;
    }
    public static int channelRows = 7;
    public static int videoRows = 3;
    public static int padding = 12;
    public static int recycleViewHeight = 720;
    public static int recycleViewHeightChannel = 720;
    static Toast mToast;
    static TextView toastTextView;
    public static void show(int size, String Info, boolean isLong) {
        if (mToast == null) {
            mToast = new Toast(mMainApp);
        }
        if (toastTextView == null) {
            toastTextView = new TextView(mMainApp);
        }

        if (isLong) {
            mToast.setDuration(Toast.LENGTH_LONG);
        } else {
            mToast.setDuration(Toast.LENGTH_SHORT);
        }

        mToast.setGravity(Gravity.CENTER, 0, 0);
        toastTextView.setTextSize(size);
        toastTextView.setPadding(50, 65, 50, 65);
        toastTextView.setBackgroundResource(R.drawable.background_corner);
        //toastTextView.getBackground().setAlpha(200);
        toastTextView.setText(Info);
        toastTextView.setTextColor(Color.WHITE);
        mToast.setView(toastTextView);
        mToast.show();
    }
}
